package com.sghd.fight.module.game.service.skill.effect;

import com.sghd.fight.module.game.config.SkillConfig;
import com.sghd.fight.module.game.core.model.Unit;
import com.sghd.fight.module.game.service.room.IRoom;
import com.sghd.fight.module.game.service.skill.ConfigService;
import com.sghd.fight.module.game.service.skill.Context;
import com.sghd.pojo.fight.game.SkillReport;
import com.sghd.pojo.fight.game.TargetReport;
import com.sghd.pojo.fight.game.UnitValue;
import com.sghd.pojo.fight.game.ValueItem;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author frank
 * @date 2018-11-21 15:27
 * @desc 恢复
 **/
@Component
public class RecoverEffect implements Effect {
    @Autowired
    private ConfigService configService;

    @Override
    public void execute(Context context, IRoom room, Unit owner, Unit target, Map<String, Object> ctx, SkillReport skillReport, TargetReport targetReport, SkillConfig config) {

        int level = owner.getSkillLevel(config.getId());
        Map<String, Object> level2Recover = MapUtils.getMap(ctx, String.valueOf(level));
        //恢复3HP
        int recover = MapUtils.getIntValue(level2Recover, Effect.RECOVER);
        recover += getAddedHp(owner, room, config.getType());//五行额外提供的hp

        context.addValue(target, UnitValue.HP, recover);
        targetReport.addValue(ValueItem.valueOf(UnitValue.HP, recover));
    }

    @Override
    public EffectType getType() {
        return EffectType.SK_RECOVER;
    }
}
